﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Office.Interop;
using Microsoft.Office.Interop.Word;
using System.Data;

namespace RenShiPinYongBiao
{
    class WordExporterTemplate
    {
        private string tFileName;
        private List<string> texts=new List<string>();
        private string oFileName;
        private object missing = Type.Missing;
        public WordExporterTemplate(string templateFileName)
        {
            this.tFileName = templateFileName;
            this.oFileName = Environment.CurrentDirectory + "\\专业技术人员聘任登记表.doc";

        }
        public void Export(DataTable dt)
        {
            DataSourceTech dstech = new DataSourceTech(dt);
            Application app = new ApplicationClass();
            Document doc = app.Documents.Add(tFileName, missing, missing, true);
            doc.Activate();
            WordPageBuilderTech wpb = new WordPageBuilderTech(dstech, app);
            wpb.BuildArch(dt.Rows.Count);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                wpb.BuildPage();
                wpb.NextPage();
            }
            doc.SaveAs(oFileName);
            app.Quit();
        }
        public void Export(string oFileName,DataTable dt)
        {
            this.oFileName = oFileName;
            this.Export(dt);
        }
    }
}
